﻿@using KPIS.GERP.Models.ICM
@model IEnumerable<KPIS.GERP.Models.ICM.MasDepreciationType>

@{
    ViewBag.Title = "อัตราค่าเสื่อมราคาสินทรัพย์ถาวร";
}


@using (Html.BeginForm("DeleteAll", "MasDepreciationType", FormMethod.Post, new { @id = "form" }))
{
    @Html.AntiForgeryToken()
    <div class="row-fluid">
        <div class="block-button-menu-above">
            @Html.ButtonAdd()
            @Html.ButtonDeleteAll()
        </div>

        @Html.ValidationSummary(true, "", new { @class = "alert alert-error" })

    <div class="row-fluid">
    <div class="table-header span12">
        <div class="span10">
            @ViewBag.Title
        </div>
        @Html.Partial("_ExportButton")
    </div>
</div>
    <table id="table" class="table table-striped table-bordered table-hover"
        aria-describedby="table_receive_parcel_info">
        <thead>
            <tr>
                <th class="center">
                    <label>
                        <input type="checkbox" />
                        <span class="lbl"></span>
                    </label>

                </th>
                <th style="text-align:center">@Html.DisplayNameFor(model=>model.Name)</th>
                <th style="text-align:center">@Html.DisplayNameFor(model=>model.MinLifeYear)</th>
                <th style="text-align:center">@Html.DisplayNameFor(model=>model.MinRateYear)</th>
                <th style="text-align:center">@Html.DisplayNameFor(model=>model.MaxLifeYear)</th>
                <th style="text-align:center">@Html.DisplayNameFor(model=>model.MaxRateYear)</th>
                @*<th style="text-align:center">@Html.DisplayNameFor(model=>model.DpRateYear)</th>*@
                <th style="text-align:center">@Html.DisplayNameFor(model=>model.ScrapValue)</th>
                <th>&nbsp;</th>
            </tr>
        </thead>

        <tbody>
            @foreach(var m in Model)
            {
                <tr>
                <td class="center">
                    <label>
                        <input id="selAll" type="checkbox"  name="deleteIds" value="@(m.DpTypeId)"  />
                        <span class="lbl"></span>
                    </label>
                </td>
                <td>@Html.ActionLink(@m.Name, "Details", new { Id=m.DpTypeId })</td>
                <td style="text-align:right">@Html.DisplayFor(Item => m.MinLifeYear)</td>
                <td style="text-align:right">@Html.DisplayFor(Item => m.MinRateYear)</td>
                <td style="text-align:right">@Html.DisplayFor(Item => m.MaxLifeYear)</td>
                <td style="text-align:right">@Html.DisplayFor(Item => m.MaxRateYear)</td>
                @*<td style="text-align:right">@Html.DisplayFor(Item => m.DpRateYear)</td>*@
                <td style="text-align:right">@Html.DisplayFor(Item => m.ScrapValue)</td>
                <td class="td-actions">
                    <div class="hidden-phone visible-desktop btn-group">
                        @Html.ButtonDetails(new { id = m.DpTypeId}, true)
                        @Html.ButtonEdit(new { id = m.DpTypeId}, true)
                        @Html.ButtonDelete(new { id = m.DpTypeId}, true)
                    </div>
                </td>
            </tr>
            }

        </tbody>
    </table>
</div>
}


@section scripts {

    
    <script type="text/javascript">
        function DelEvent() {
            bootbox.alert("ถ้าต้องการลบรายการนี้ กรุณาเข้าไปลบรายละเอียดให้หมดก่อน จึงจะสามารถลบได้");
        }


        $(function () {
            var oTable1 = $('#table').dataTable({
                "aoColumns": [
                  { "bSortable": false },
                  null, null, null, null, null, null, 
                  { "bSortable": false }
                ]
            });
            $('table th input:checkbox').on('click', function () {
                var that = this;
                $(this).closest('table').find('tr > td:first-child input:checkbox')
                .each(function () {
                    this.checked = that.checked;
                    $(this).closest('tr').toggleClass('selected');
                });

            });

            $('[data-rel=tooltip]').tooltip();

            $("#form").submit(function (e) {
                e.preventDefault();
                var currentForm = this;
                bootbox.confirm("คุณแน่ใจหรือไม่", function (c) {
                    if (c) {
                        $.ajax({
                            url: "@Url.Action("DeleteAll")",
                            type: "post",
                            dataType: "json",
                            data: $(currentForm).serialize(),
                            context: document.body,
                            success: function (s) {
                                if (s.success) {
                                    location.reload();
                                }
                            },
                            error: function (xhr, status, error) {
                                alert("Status: " + status + ", Error: " + error + ", XHR: " + xhr.readyState);
                            },
                            statusCode: {
                                404: function () {
                                    alert("Page not found");
                                }
                            }
                        });
                    }
                })
                return false;
            });
        })




    </script>

}
